<!DOCTYPE html>
<html>

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no"/>
    <title>设备定位</title>
    <link rel="stylesheet" href="css/demo.css">
    <script src="js/configData.js"></script>
    <script src="libs/axios.min.js"></script>
    <script src="libs/httpService.js"></script>
    <script src="js/demo.js"></script>
</head>
<body id="body">
<div id='map'></div>
<div class="opt_panel">
    <button onclick="onLocateByCenter()">中心-设备定位</button>
    <button onclick="onLocateByBounds()">范围-设备定位</button>
    <button onclick="changeFlicker()">开启/关闭闪烁</button>
</div>
</body>
</html>

<script>

    var locateTool
    var isFlickering = true
    function changeFlicker(){
        isFlickering = !isFlickering
        map.egis.selectionSet.setFlicker(isFlickering)
    }
    function onLocateByCenter() {
        //设置高亮颜色
        map.egis.selectionSet.setAutoFlicker(false)
        map.egis.selectionSet.setSelectionColor('#00ff00')
        //指定地图中心点和层级
        let center = [
            118.19020154620375, 24.484232695304414
        ]

        locateTool.locateByCenter({
            '305000': ['1055351'],
            '360000': ['11554968']
        }, center, 22)
    }

    function onLocateByBounds() {
        map.egis.selectionSet.setAutoFlicker(true)
        map.egis.selectionSet.setSelectionColor('#ffff00')
        let bounds = [
            [118.19015084157007, 24.48421149716704],
            [118.19024857616125, 24.484253893426896]
        ]

        locateTool.locateBybounds({
            '305000': ['1062835'],
            '360000': ['11554968']
        }, bounds)
    }
    function initPage(){

        mapServiceUrl = msServiceUrl + '/mapservice/mapexport/vecformat'
        initGridLayer()

        initSnapTool()
        initSelectTool()

        //为选择集指定第三方数数据源
        //适用范围：用户自行创建layer绘制的XX图，需要在这里把数据返回给SelectionSet来让SelectionSet获取相关的设备样式
        // 【适用GridVectorlayer和GridTileLayer则不需要指定数据源回调】

        // map.egis.selectionSet.setDataSourceCallback(cb => {
        //     for (let lId in map.powerGridDevs.data) {
        //         let lData = map.powerGridDevs.data[lId]
        //         let type = lData.type
        //         for (let i = 0; i < lData.features.length; i++) {
        //             cb(type, lData.features[i])
        //         }
        //     }
        //
        // })
        locateTool = new egisV2.tool.LocateTool(map)
    }

    window.onload = function () {
        loadGeoMap_ms(initPage)
    }

</script>
